/**
 * @Classname QuartzConfig
 * @Description TODO
 * @author Tale-Mi
 * @date 2019/3/11 20:52
 */
package org.tale.mscp.notify.config;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.tale.mscp.notify.job.KqNotifyDayJob;
import org.tale.mscp.notify.job.KqNotifyTimeJob;

@Configuration
public class QuartzConfig {


    // 使用jobDetail包装job
    @Bean
    public JobDetail kqNotifyTimeJob() {
        return JobBuilder.newJob(KqNotifyTimeJob.class).withIdentity("kqNotifyTimeJob").storeDurably().build();
    }

    @Bean
    public JobDetail kqNotifyDayJob() {
        return JobBuilder.newJob(KqNotifyDayJob.class).withIdentity("kqNotifyDayJob").storeDurably().build();
    }

    // 把jobDetail注册到Cron表达式的trigger上去
    @Bean
    public CronTrigger timeJobTrigger() {
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 50 12,18 ? * 2-7 *");
//        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 0/1 * * * ?");

        return TriggerBuilder.newTrigger()
                .forJob(kqNotifyTimeJob())
                .withIdentity("timeJobTrigger")
                .withSchedule(cronScheduleBuilder)
                .build();
    }

    @Bean
    public CronTrigger dayJobTrigger() {
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 50 19 ? * 2-7 *");
//        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0/10 * * * * ?");

        return TriggerBuilder.newTrigger()
                .forJob(kqNotifyDayJob())
                .withIdentity("dayJobTrigger")
                .withSchedule(cronScheduleBuilder)
                .build();
    }
}
